package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.PreloadSeniorDeviceAndApp;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by Administrator on 2016/5/13.
 */
public class PreloadSeniorDeviceAndAppConvert {
    public static DBObject castPreloadSeniorDeviceAndAppToDBObject(PreloadSeniorDeviceAndApp preloadSeniorDeviceAndApp){
        DBObject dbo = new BasicDBObject();
        if(preloadSeniorDeviceAndApp.getId() != null){
            dbo.put("_id",preloadSeniorDeviceAndApp.getId());
        }
        if(preloadSeniorDeviceAndApp.getDeviceId() != null)
            dbo.put("deviceId",preloadSeniorDeviceAndApp.getDeviceId());

        if(preloadSeniorDeviceAndApp.getAppId() != null)
            dbo.put("appId",preloadSeniorDeviceAndApp.getAppId());

        if(preloadSeniorDeviceAndApp.getSysType() != null)
            dbo.put("sysType",preloadSeniorDeviceAndApp.getSysType());


        if(preloadSeniorDeviceAndApp.getSysVersion() != null)
            dbo.put("sysVersion",preloadSeniorDeviceAndApp.getSysVersion());

        return dbo;


    }

    public static PreloadSeniorDeviceAndApp castDBObjectToPreloadSeniorDeviceAndApp(DBObject dbObject){
        PreloadSeniorDeviceAndApp preloadSeniorDeviceAndApp = new PreloadSeniorDeviceAndApp();
        if(dbObject != null) {
            preloadSeniorDeviceAndApp.setId(ObjUtils.toLong(dbObject.get("_id")));
            preloadSeniorDeviceAndApp.setDeviceId(ObjUtils.toLong(dbObject.get("deviceId")));
            preloadSeniorDeviceAndApp.setAppId(ObjUtils.toLong(dbObject.get("appId")));
            preloadSeniorDeviceAndApp.setSysType(ObjUtils.toInteger(dbObject.get("sysType")));
            preloadSeniorDeviceAndApp.setSysVersion(ObjUtils.toString(dbObject.get("sysVersion")));
        }

        return preloadSeniorDeviceAndApp;
    }
}
